﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Domain.PermisosModule.Resources;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Domain.Core.Specification;

namespace Cesave.Domain.PermisosModule.Contracts.Usuarios
{
	/// <summary>
	/// 
	/// </summary>
	public class UsuarioByPadronSpecification
		: Specification<Usuario>
	{
		#region Private properties

		/// <summary>
		/// 
		/// </summary>
		private string _padron = default(string);

		/// <summary>
		/// 
		/// </summary>
		private string _subPadron = default(string);

		/// <summary>
		/// 
		/// </summary>
		private string _control = default(string);

		#endregion

		#region Constructor

		/// <summary>
		/// 
		/// </summary>
		/// <param name="padron"></param>
		/// <param name="subPadron"></param>
		/// <param name="control"></param>
		public UsuarioByPadronSpecification(string padron, string subPadron, string control)
		{
			if (string.IsNullOrEmpty(padron))
				throw new ArgumentNullException(Messages.exception_InvalidArgument, "padron");
			if (string.IsNullOrEmpty(subPadron))
				throw new ArgumentNullException(Messages.exception_InvalidArgument, "subPadron");
			if (string.IsNullOrEmpty(control))
				throw new ArgumentNullException(Messages.exception_InvalidArgument, "control");
			_padron = padron;
			_subPadron = subPadron;
			_control = control;
		}

		#endregion

		#region Specification overrides

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public override System.Linq.Expressions.Expression<Func<Usuario, bool>> SatisfiedBy()
		{
			Specification<Usuario> specification = new TrueSpecification<Usuario>();
			specification &= new DirectSpecification<Usuario>(u => u.Padron == _padron);
			specification &= new DirectSpecification<Usuario>(u => u.SubPadron == _subPadron);
			specification &= new DirectSpecification<Usuario>(u => u.Control == _control);
			return specification.SatisfiedBy();
		}

		#endregion
	}
}
